{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-12T03:50:43.011818Z",
     "start_time": "2025-05-12T03:50:42.931933Z"
    }
   },
   "source": "from sklearn.preprocessing import MinMaxScaler",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-12T03:53:21.541848Z",
     "start_time": "2025-05-12T03:53:21.535847Z"
    }
   },
   "cell_type": "code",
   "source": [
    "X = [[2, 1], [3, 1], [1, 4], [2, 6]]\n",
    "\n",
    "scaler = MinMaxScaler(feature_range=(-1, 1))\n",
    "\n",
    "X_scaled = scaler.fit_transform(X)\n",
    "\n",
    "print(X_scaled)"
   ],
   "id": "e7ad39a1587a25c1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  -1. ]\n",
      " [ 1.  -1. ]\n",
      " [-1.   0.2]\n",
      " [ 0.   1. ]]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-12T06:16:08.249749Z",
     "start_time": "2025-05-12T06:16:08.245742Z"
    }
   },
   "cell_type": "code",
   "source": "from sklearn.preprocessing import StandardScaler",
   "id": "5c12ea676453811e",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-12T06:17:19.787145Z",
     "start_time": "2025-05-12T06:17:19.781143Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 标准化\n",
    "scaler = StandardScaler()\n",
    "X_scaled = scaler.fit_transform(X)\n",
    "\n",
    "print(X_scaled)"
   ],
   "id": "a1e06705b3e08b49",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.         -0.94280904]\n",
      " [ 1.41421356 -0.94280904]\n",
      " [-1.41421356  0.47140452]\n",
      " [ 0.          1.41421356]]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-12T06:20:30.773497Z",
     "start_time": "2025-05-12T06:20:30.767049Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np \n",
    "X = np.array(X)\n",
    "\n",
    "# 计算均值和标准方差\n",
    "mean = np.mean(X, axis=0)\n",
    "std = np.std(X, axis=0)\n",
    "\n",
    "print((X - mean)/std)"
   ],
   "id": "6d947454cf8ba2b8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.         -0.94280904]\n",
      " [ 1.41421356 -0.94280904]\n",
      " [-1.41421356  0.47140452]\n",
      " [ 0.          1.41421356]]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "79c52c4721de30fc"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
